home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 755 < prev    next >
Encoding:
Text File  |  1996-08-06  |  4.2 KB  |  152 lines

  1. Path: ix.netcom.com!netnews
  2. From: wells2@ix.netcom.com (wells)
  3. Newsgroups: comp.lang.c++
  4. Subject: need help with a program mfc
  5. Date: Sat, 06 Jan 1996 21:11:09 GMT
  6. Organization: Netcom
  7. Message-ID: <4cmqhh$arb@ixnews5.ix.netcom.com>
  8. NNTP-Posting-Host: irv-ca16-17.ix.netcom.com
  9. X-NETCOM-Date: Sat Jan 06  1:45:21 PM PST 1996
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12.  
  13. I am new to the mfc library and i need some help. I want to take this
  14. sample prgram and add a second dialog box to it. Can anyone do this so
  15. i can look it over??? I know i have to add the second dialog to the
  16. resource but besides that, I want to see how you do it. I have tried
  17. but i keep getting errors and i dont understand what i am doing wrong.
  18. I am using Microsoft Visual C++ ver 1.0
  19.  
  20. thanks you very much in advanced 
  21. i greatly appreaciate it!!!!
  22. :)
  23.  
  24.  
  25. here it is......
  26.  
  27.  
  28.  
  29.  
  30. // hello.cpp : Defines the class behaviors for the application.
  31. //           Hello is a simple program which consists of a main window
  32. //           and an "About" dialog which can be invoked by a menu
  33. choice.
  34. //           It is intended to serve as a starting-point for new
  35. //           applications.
  36. //
  37. // This is a part of the Microsoft Foundation Classes C++ library.
  38. // Copyright (C) 1992 Microsoft Corporation
  39. // All rights reserved.
  40. //
  41. // This source code is only intended as a supplement to the
  42. // Microsoft Foundation Classes Reference and Microsoft
  43. // WinHelp documentation provided with the library.
  44. // See these sources for detailed information regarding the
  45. // Microsoft Foundation Classes product.
  46.  
  47. #include "stdafx.h"
  48. #include "resource.h"
  49.  
  50. #include "hello.h"
  51.  
  52. /////////////////////////////////////////////////////////////////////////////
  53.  
  54. // theApp:
  55. // Just creating this application object runs the whole application.
  56. //
  57. CTheApp NEAR theApp;
  58.  
  59. /////////////////////////////////////////////////////////////////////////////
  60.  
  61. // CMainWindow constructor:
  62. // Create the window with the appropriate style, size, menu, etc.
  63. //
  64. CMainWindow::CMainWindow()
  65. {
  66.     LoadAccelTable( "MainAccelTable" );
  67.     Create( NULL, "Hello Foundation Application",
  68.         WS_OVERLAPPEDWINDOW, rectDefault, NULL, "MainMenu" );
  69. }
  70.  
  71. // OnPaint:
  72. // This routine draws the string "Hello, Windows!" in the center of
  73. the
  74. // client area.  It is called whenever Windows sends a WM_PAINT
  75. message.
  76. // Note that creating a CPaintDC automatically does a BeginPaint and
  77. // an EndPaint call is done when it is destroyed at the end of this
  78. // function.  CPaintDC's constructor needs the window (this).
  79. //
  80. void CMainWindow::OnPaint()
  81. {
  82.     CString s = "Hello, Windows!";
  83.     CPaintDC dc( this );
  84.     CRect rect;
  85.  
  86.     GetClientRect( rect );
  87.     dc.SetTextAlign( TA_BASELINE | TA_CENTER );
  88.     dc.SetTextColor( ::GetSysColor( COLOR_WINDOWTEXT ) );
  89.     dc.SetBkMode(TRANSPARENT);
  90.     dc.TextOut( ( rect.right / 2 ), ( rect.bottom / 2 ),
  91.                 s, s.GetLength() );
  92. }
  93.  
  94. // OnAbout:
  95. // This member function is called when a WM_COMMAND message with an
  96. // IDM_ABOUT code is received by the CMainWindow class object.  The
  97. // message map below is responsible for this routing.
  98. //
  99. // We create a ClDialog object using the "AboutBox" resource (see
  100. // hello.rc), and invoke it.
  101. //
  102. void CMainWindow::OnAbout()
  103. {
  104.     CDialog about( "AboutBox", this );
  105.     about.DoModal();
  106. }
  107.  
  108. // CMainWindow message map:
  109. // Associate messages with member functions.
  110. //
  111. // It is implied that the ON_WM_PAINT macro expects a member function
  112. // "void OnPaint()".
  113. //
  114. // It is implied that members connected with the ON_COMMAND macro
  115. // receive no arguments and are void of return type, e.g., "void
  116. OnAbout()".
  117. //
  118. BEGIN_MESSAGE_MAP( CMainWindow, CFrameWnd )
  119.     //{{AFX_MSG_MAP( CMainWindow )
  120.     ON_WM_PAINT()
  121.     ON_COMMAND( IDM_ABOUT, OnAbout )
  122.     //}}AFX_MSG_MAP
  123. END_MESSAGE_MAP()
  124.  
  125. /////////////////////////////////////////////////////////////////////////////
  126. // CTheApp
  127.  
  128. // InitInstance:
  129. // When any CTheApp object is created, this member function is
  130. automatically
  131. // called.  Any data may be set up at this point.
  132. //
  133. // Also, the main window of the application should be created and
  134. shown here.
  135. // Return TRUE if the initialization is successful.
  136. //
  137. BOOL CTheApp::InitInstance()
  138. {
  139.     TRACE( "HELLO WORLD\n" );
  140.  
  141.     SetDialogBkColor();     // hook gray dialogs (was default in MFC V1)
  142.  
  143.     m_pMainWnd = new CMainWindow();
  144.     m_pMainWnd->ShowWindow( m_nCmdShow );
  145.     m_pMainWnd->UpdateWindow();
  146.  
  147.     return TRUE;
  148. }
  149.  
  150.  
  151.  
  152.